package plus.xj17520.org.controller;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import plus.xj17520.annotation.MyLog;
import plus.xj17520.org.domain.User;
import plus.xj17520.org.service.IUserService;
import plus.xj17520.base.query.UserQuery;
import plus.xj17520.base.result.JSONResult;

/**
 * @projectName: pethomeProject
 * @package: plus.xj17520.org.controller
 * @className: UserController
 * @author: XiaoJue
 * @description: TODO
 * @date: 2022/5/23 15:29
 * @version: 1.0
 */
@RestController
@RequestMapping("user")
@Api(value = "用户管理的接口文档",description = "用户管理的接口文档")
public class UserController {
    @Autowired
    IUserService userService;

    @ApiOperation(value = "查询单个用户对象",notes = "此方法的具体说明在这里描述")
    @GetMapping("findOne/{id}")
    public JSONResult findOne(@ApiParam(value = "用户id") @PathVariable Long id){
        return userService.findOne(id);
    }

    @ApiOperation(value = "查询用户的所有对象",notes = "此方法的具体说明在这里描述")
    @PostMapping("all")
    public JSONResult findAll(){
        return userService.findAll();
    }

    @ApiOperation(value = "新增一个用户对象",notes = "此方法的具体说明在这里描述")
    @PostMapping("add")
    public JSONResult add(@RequestBody User user){
        return userService.addOrUpdate(user);
    }

    @ApiOperation(value = "删除一个用户对象",notes = "此方法的具体说明在这里描述")
    @GetMapping("delete/{id}")
    @MyLog(title = "用户模块", content = "删除用户操作")
    public JSONResult delete(@ApiParam(value = "用户实例对象的id") @PathVariable Long id){
        return userService.delete(id);
    }

    @ApiOperation(value = "修改一个用户对象",notes = "此方法的具体说明在这里描述")
    @PostMapping("update")
    public JSONResult update(@RequestBody User user){
        return userService.addOrUpdate(user);
    }

    @ApiOperation(value = "分页，高级查询",notes = "此方法的具体说明在这里描述")
    @PostMapping("query")
    public JSONResult query(@RequestBody UserQuery userQuery){
        return userService.userPageList(userQuery);
    }

    @ApiOperation(value = "批量删除",notes = "此方法的具体说明在这里描述")
    @PostMapping("batchDelete")
    public JSONResult batchDelete(@RequestBody UserQuery userQuery){
        return userService.batchDelete(userQuery);
    }
}
